package com.rub.android.jetpack.viewmodel

import androidx.databinding.ObservableField
import com.rub.android.jetpack.model.User

/**
 * 双向绑定
 * @Bindable 注解报错解决
 *
 * https://kotlinlang.org/docs/reference/kapt.html
 * https://stackoverflow.com/questions/47044955/kapt-generatestubs-is-not-used-by-the-kotlin-kapt-plugin
 * apply plugin: 'kotlin-kapt'
 * To use data binding annotations in Kotlin, apply the 'kotlin-kapt' plugin in your module's build.gradle
 */
class UserViewModel2() {

    private var userObservableField: ObservableField<User>


    init {
        val user = User("蹭蹭")
        userObservableField = ObservableField()
        userObservableField.set(user)
    }

    fun getUserName() = userObservableField.get()?.userName


    fun setUserName(userName: String) {
        userObservableField.get()?.userName = userName
    }

}